﻿package core.ui.controls
{
    import core.enum.*;
    import core.image.*;
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;

    public class BrushPad extends Sprite
    {
        var ed:Tuyitu;
        var pad:Bitmap;
        var lb:TextField;
        public var shape:Brush;

        public function BrushPad(param1:Tuyitu)
        {
            this.ed = param1;
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.MouseDown, false, 1, true);
            this.graphics.beginFill(16777215, 0);
            this.graphics.drawRect(0, 0, 42, 22);
            this.graphics.endFill();
            this.pad = new Bitmap();
            this.pad.y = 1;
            addChild(this.pad);
            var _loc_2:* = new Bitmap(new More());
            _loc_2.x = 27;
            _loc_2.y = 13;
            addChild(_loc_2);
            this.lb = new TextField();
            this.lb.defaultTextFormat = new TextFormat("Verdana, Helvetica, San-serif", 9, 3355443, false, false, false, null, null, "center");
            this.lb.multiline = false;
            this.lb.selectable = false;
            this.lb.height = 14;
            this.lb.width = 28;
            this.lb.y = -1;
            this.lb.x = 17;
            addChild(this.lb);
            this.SetBrush(param1.options.brushes.brushes.length > 15 ? (param1.options.brushes.brushes[15]) : (param1.options.brushes.shape));
            return;
        }// end function

        public function MouseDown(event:MouseEvent) : void
        {
            this.ed.options.brushes.Show(this);
            this.ed.options.brushes.x = this.x + 40;
            this.ed.options.brushes.y = this.y + 29;
            return;
        }// end function

        public function SetBrush(height:Brush) : void
        {
            this.shape = height;
            this.lb.text = height.type != BrushType.Custom ? ((height.details.radius * 2).toString()) : (height.size.toString());
            this.pad.bitmapData = height.GenerateThumb(19).clone();
            this.pad.y = Math.round((20 - this.pad.height) / 2);
            this.pad.x = Math.round((18 - this.pad.width) / 2);
            return;
        }// end function

        public function SetShapeProperty(height:int, height:Boolean = false) : void
        {
            var _loc_3:ShapeDetails = null;
            var _loc_4:Number = NaN;
            var _loc_5:int = 0;
            if (this.shape.type != BrushType.Custom)
            {
                _loc_3 = this.shape.details;
                _loc_4 = height > 200 ? (height ? (0.25) : (0.1)) : (height ? (15) : (5));
                switch(height)
                {
                    case 190:
                    {
                        if (_loc_3.radius + 5 < 250)
                        {
                            _loc_3.radius = _loc_3.radius + 5;
                        }
                        else
                        {
                            _loc_3.radius = 250;
                        }
                        break;
                    }
                    case 188:
                    {
                        if (_loc_3.radius - 5 > 0.5)
                        {
                            _loc_3.radius = _loc_3.radius - 5;
                        }
                        else
                        {
                            _loc_3.radius = 0.5;
                        }
                        break;
                    }
                    case 290:
                    {
                        if (_loc_3.hardness + 0.1 < 1)
                        {
                            _loc_3.hardness = _loc_3.hardness + 0.1;
                        }
                        else
                        {
                            _loc_3.hardness = 1;
                        }
                        break;
                    }
                    case 288:
                    {
                        if (_loc_3.hardness - 0.1 > 0)
                        {
                            _loc_3.hardness = _loc_3.hardness - 0.1;
                        }
                        else
                        {
                            _loc_3.hardness = 0;
                        }
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                _loc_3.step = Math.round(_loc_3.radius / 5 + _loc_3.radius / 5 * (_loc_3.hardness / 2));
                this.SetBrush(Misc.GenerateBrush(_loc_3));
            }
            else
            {
                _loc_5 = this.shape.size;
                switch(height)
                {
                    case 190:
                    {
                        if (_loc_5 + 5 < 999)
                        {
                            _loc_5 = _loc_5 + 10;
                        }
                        else
                        {
                            _loc_5 = 999;
                        }
                        break;
                    }
                    case 188:
                    {
                        if (_loc_5 - 5 > 5)
                        {
                            _loc_5 = _loc_5 - 10;
                        }
                        else
                        {
                            _loc_5 = 5;
                        }
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                this.SetBrush(Misc.ResizeBrush(this.shape.parent ? (this.shape.parent) : (this.shape), _loc_5, 1, Math.round(_loc_5 * 0.1 + _loc_5 * 0.1 * 0.01)));
            }
            this.ed.tool.Reset();
            return;
        }// end function

    }
}
